package cn.itcast.activiti.servlet.history;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricTaskInstanceQuery;

import cn.itcast.activiti.common.ProcessEngineUtils;

/**
 * 查询历史任务
 * @author Administrator
 *
 */
@WebServlet("/queryHistoryTask.action")
public class QueryHistoryTaskServlet extends HttpServlet{

	private static final long serialVersionUID = 1217181614955703002L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//获取历史流程实例Id
		String hpiId=request.getParameter("hpiId");
		//获取流程引擎
		ProcessEngine processEngine=ProcessEngineUtils.getProcessEngine();
		//获取历史服务
		HistoryService historyService=processEngine.getHistoryService();
		//创建历史任务查询对象
		HistoricTaskInstanceQuery historicTaskInstanceQuery=historyService.createHistoricTaskInstanceQuery();
		//调用历史任务查询对象中的方法
		List<HistoricTaskInstance> htsList=historicTaskInstanceQuery.processInstanceId(hpiId).finished().orderByTaskCreateTime().asc().list();
		
		request.setAttribute("htsList", htsList);
		request.getRequestDispatcher("/historyTask.jsp").forward(request, response);;
	}

}
